package day14.Ti.XianChengChi;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class Ti01 {
    public static void main(String[] args) throws InterruptedException {
        ThreadPoolExecutor pool = new ThreadPoolExecutor(
                2,
                5,
                2,
                TimeUnit.SECONDS,
                new ArrayBlockingQueue<>(1),
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.CallerRunsPolicy());
        MyRunnable mr = new MyRunnable();
        Thread t1 = new Thread(mr);
        t1.setName("小王:");
        t1.start();
        Thread.sleep(2000);
        pool.submit(() ->
                System.out.println(Thread.currentThread().getName() +
                        "教我java,教完后，老师回到了办公室")
        );
        pool.shutdown();
    }
}

class MyRunnable implements Runnable {
    @Override
    public void run() {
        System.out.println(Thread.currentThread().getName() + "我需要一个老师");
    }
}
